package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author lwd
 * @since 2023-04-24
 */
@Mapper
public interface OrdersMapper {
    /**
     * 保存
     *
     * @param orders
     */
    void save(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     *
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据id查找该订单是否存在
     *
     * @param id
     * @return
     */
    @Select("select * from sky_take_out.orders where id =#{id}")
    Orders getByOrderId(Long id);


    OrderStatisticsVO statisticsOrder();

    Page<OrderVO> page(OrdersPageQueryDTO ordersPageQueryDTO);
@Select("select * from sky_take_out.orders where  id= #{id}")
    Orders getById(Long id);


    Page<OrderVO> historyOrders(Long userID, Integer status);

    List<OrderDetail> historyOrdersDt(Long id);

@Select("select * from sky_take_out.orders where user_id =#{userID}")
    Orders getByuserId(Long userID);
@Select("select * from sky_take_out.order_detail where order_id =#{orderId} ")
    List<OrderDetail> getByOrderid(Orders orderId);
@Select("select * from sky_take_out.orders where status = #{status} and order_time < #{dateTime}")
    List<Orders> getStatusAndTime(@Param("status") Integer pendingPayment, LocalDateTime dateTime);

    void batcupdate(@Param("ids") List<Long> ids,@Param("o") Orders build);

    List<Map> groupByAmountandStatus(Map params);

    /**
     * 查询所有订单
     * @param params
     * @return
     */
    List<Map> groupCountOrderByparams(Map params);

    /**
     *根据菜品或者套餐的名称分组查寻销量前十的菜品或者套餐
     * @param params
     * @return
     */
    List<GoodsSalesDTO> groupBySumNumber(Map params);
}
